/**
 * TestController.java
 * com.lyj.demo.springboot.controller
 * Function： TODO add descript
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2017年8月24日       lyj
 *
 * Copyright (c) 2017, TNT All Rights Reserved.
*/

package com.lyj.demo.springboot.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.lyj.demo.springboot.model.User;
import com.lyj.demo.springboot.service.TestService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

/**
 * ClassName:TestController
 * Function: TODO 此类均为集成各种插件环境测试所用，测试均在此
 * Reason:	 TODO ADD REASON
 *
 * @author   lyj
 * @version  
 * @since    version 1.0
 * @Date	 2017年8月24日	上午11:07:54
 *
 * @see 	 
 *  
 */
@RestController

@Api(value = "swagger2") // swagger2 注解；UI 访问路径：http://ip:port/swagger-ui.html
public class TestController {
	 private final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	TestService testService;

    /**
     * home:test 根 方法
     * TODO 测试spring 注解，扫描，访问等功能
     *
     * @param  @return    
     * @return String    
     * @throws 
     * @since  　version 1.0
    */
    /**
     * boot 集成 ok
     * @return
     */
    @RequestMapping("/test")
    public String home() {
        return "Hello Worl";
    }
    /**
     * mybatis 集成测试  ok
     * @return
     */
    @RequestMapping("/mybatis")
    public Integer mybatisTest(){
    	
    	return testService.count();
    	
    }
    
    /**
     * pagehelper 集成测试  ok
     * @return
     */
    @RequestMapping("/page")
    public PageInfo<User>  page(){
    	logger.info("liyajie ****:{}",1);
    	
    	return testService.page();
    	
    }
    
    
    /**
     * swagger2 集成测试  ok
     * @return
     */
    
    
    @ApiOperation(value = "swagger2 测试", notes = "测试，，，，，，")  
    @ApiImplicitParams({@ApiImplicitParam(name = "xx", value = "xx不问原因", required = true, dataType = "String"),  
    })  
    @RequestMapping(value="/api/{xx}",method = RequestMethod.GET)
    public String  swagger2(@PathVariable("xx") String xx){
    	logger.info("swagger2 ****:{}", "good!");
    	
    	return "hello swagger2!"+xx;
    	
    }
    
    
    
    @ApiOperation(value = "swagger2 json对象测试", notes = "jsonobject")  
    @ApiImplicitParams({@ApiImplicitParam(name = "object", value = "json对象", required = true,dataType = "JSONObject"),  
    })  
    @RequestMapping(value="/api/model",method = RequestMethod.POST)
    public String  model(JSONObject object){
    	logger.info("swagger2 ****:{}", "good!");
    	
    	return "hello swagger2!"+object.getString("id");
    	
    }
    
    
    @ApiOperation(value = "swagger2 model测试", notes = "model put 测试")  
    @ApiImplicitParams({@ApiImplicitParam(name = "user", value = "用户", required = true,dataType = "User"),  
    })  
    
    @ApiResponse( code = 200, message = "success!")
    @RequestMapping(value="/api/model",method = RequestMethod.PUT)
    
    public User  model(@RequestBody User user){
    	logger.info("swagger2 ****:{}", "good!");
    	
    	return user ;
    	
    }
}
